
import { createStore } from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import app from "./app";
import defaultStore from './defaultStore'
import persistedState from 'vuex-persistedstate'
import menuParamStore from './menuParamStore'
export interface State {
    collapse: boolean,
    tagsLists: any[],
    activeModules: string,
    themeVal: string,
    themeColor: string,
    permissionList: any[]
}

export default createStore({
    state: {
        collapse: false,//菜单展开折叠方向
        /*标签列表，默认显示首页*/    
        tagsLists: [{path: '/'}],
        activeModules: '',
        themeVal: 'light',
        themeColor: '#0052d9',
        permissionList: []
    },
    mutations: {
        setCollapse(state: State, collapse){
            state.collapse = collapse;
        },
        setTagsLists(state: State, tagsLists){
            state.tagsLists = tagsLists;
        },
        setActiveModules(state: State, activeModules){
            state.activeModules = activeModules;
        },
        setThemeVal(state: State, themeVal){
            state.themeVal = themeVal;
        },
        setThemeColor(state: State, themeColor){
            state.themeColor = themeColor;
        },
        setPermissionList(state: State, permissionList){
            state.permissionList = permissionList;
        }
    },
    getters: {
        collapse: (state: State): boolean => state.collapse,
        tagsLists: (state: State): any=> state.tagsLists,
        activeModules: (state: State): string=> state.activeModules,
        themeVal: (state: State)=> state.themeVal,
        themeColor: (state: State)=>state.themeColor,
        permissionList: (state: State)=> state.permissionList
    },
    actions: {
        /**
         * 关闭所有
         * @param commit
         * @param getters
         * @param dispatch
         */
        // resetTabList({commit, getters, dispatch}){
        // commit("resetList", [{'title': '首页', 'router': '/app/index', isActive: false, 'code': '000', 'name': 'Index'}]);
        // commit("setActiveTab", 'Index');
        // router.push('/');
        // },
        changeSetting({ commit }, data) {
            // commit('CHANGE_SETTING', data)
            // setTheme(data.value);
        }
    },
    modules: {
        app: app,
        ...defaultStore,
        ...menuParamStore,
    },
    plugins: [createPersistedState({
        // 默认位置localStorage
        storage: window.sessionStorage}
    )]
});